package entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;

class Personnel {
    private String id;  // 编号
    private String name;  // 名字
    private String tel;  // 电话
    private String mail;  // 邮箱
    private String addr;  // 地址
    private Date joinDate;  // 录入时间
    private List productsid = new ArrayList<String>(); // 关联的订单/采购单
    private int delFlag;    // 是否被删除

    public Personnel(String id, String name, String tel, String mail, String addr, Date joinDate, List productsid, int delFlag) {
        this.id = id;
        this.name = name;
        this.tel = tel;
        this.mail = mail;
        this.addr = addr;
        this.joinDate = joinDate;
        if(productsid != null){
            this.productsid = productsid;
        }
        this.delFlag = delFlag;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

    public Date getJoinDate() {
        return joinDate;
    }

    public void setJoinDate(Date joinDate) {
        this.joinDate = joinDate;
    }

    public List getProductsid() {
        return productsid;
    }

    public void setProductsid(List productsid) {
        this.productsid = productsid;
    }

    public int getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(int delFlag) {
        this.delFlag = delFlag;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Personnel)) return false;
        Personnel personnel = (Personnel) o;
        return getDelFlag() == personnel.getDelFlag() &&
                getId().equals(personnel.getId()) &&
                getName().equals(personnel.getName()) &&
                getTel().equals(personnel.getTel()) &&
                getMail().equals(personnel.getMail()) &&
                getAddr().equals(personnel.getAddr()) &&
                getJoinDate().equals(personnel.getJoinDate()) &&
                getProductsid().equals(personnel.getProductsid());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getId(), getName(), getTel(), getMail(), getAddr(), getJoinDate(), getProductsid(), getDelFlag());
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", Personnel.class.getSimpleName() + "[", "]")
                .add("id='" + id + "'")
                .add("name='" + name + "'")
                .add("tel='" + tel + "'")
                .add("mail='" + mail + "'")
                .add("addr='" + addr + "'")
                .add("joinDate=" + joinDate)
                .add("productsid=" + productsid)
                .add("delFlag=" + delFlag)
                .toString();
    }

    public void insert(String productName){
        this.productsid.add(productName);
    }
    public void delete(String productName){
        this.productsid.remove(productName);
    }
}
